<template>
    <div class="listItem">
        <div class="listItem_left">
            <img class="img" v-if="isImg(row?.productImage)" :src="isImg(row?.productImage)" alt="" />
            <img class="img" v-else src="@/assets/home/error.png" alt="" />
            <div class="img_tag" v-if="props.row?.hmStockMechanismsList[1].cooperationMode"></div>
            <div class="describe_department" v-if="row?.coreName">
                <van-image :src="icon_bumen"></van-image>
                <div class="coreName">{{ row?.coreName }}</div>
            </div>
        </div>
        <div class="listItem_right">
            <div class="top_box_title">
                <div class="title">{{ row?.styleName || '' }}</div>
                <div :class="{ title_tag: true, ...isStatusColour(row.sampleStatusName) }">
                    {{ row.sampleStatusName }}
                </div>
            </div>
            <div class="top_box_text">类目：{{ row?.productCategoryName || '' }}</div>
            <div class="top_box_supplier">
                <div class="top_box_supplier_text">
                    <img class="top_box_supplier_img" :src="icon_gongyingshang" alt="">
                    <span class="top_box_supplier_text_name">{{ row?.supplierName || '' }}</span>
                </div>
            </div>
            <div class="top_box_number">
                <div class="number_one">
                    <span class="one_span">￥</span>{{ isPrice(mechanism() && mechanism()[0]) }}
                </div>
                <div class="number_two" v-if="mechanism() && mechanism()[0].cooperationMode === '分佣'">
                    <div class="two_left">佣</div>
                    <div class="two_right">{{ mechanism() && mechanism()[0].commission }}%</div>
                </div>

            </div>
            <div class="top_box_time">
                <div class="top_box_time_item">邀约数量:{{ Number(row?.sampleNum) }}</div>
                <div class="top_box_time_item">邀约时间:{{ row?.sampleRequestTime.split(' ')[0] }}</div>
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
import { defineProps } from 'vue'
import { getEnvValue } from "@/utils/index";
const icon_imgNull = new URL("@/assets/newui/imgNull.jpg", import.meta.url).href;
const icon_gongyingshang = new URL("@/assets/newui/supplier/icon_gongyingshang.png", import.meta.url).href;
const icon_bumen = new URL("@/assets/productHome/icon_bumen.png", import.meta.url).href;
const props = defineProps(['row', 'isTime'])

// 图片路径处理
const isImg = (url: string | null) => {
    if (url) {
        let imgArr = url?.split(',')
        if (imgArr?.length) {
            return `${getEnvValue("VITE_APP_PIC_URL")}${imgArr[0]}?x-oss-process=image/resize,w_300`
        } else {
            return icon_imgNull;
        }
    } else {
        return icon_imgNull
    }
}
// 状态颜色区分
const isStatusColour = (type) => {
    if (type === '响应中') {
        return { "title_tag_lan": true }
    } else if (type === '已入库') {
        return { "title_tag_lv": true }
    } else if (type === '已拒绝') {
        return { "title_tag_hong": true }
    } else if (type === '已响应') {
        return { "title_tag_cheng": true }
    }
}
// 售价与成本区分
const isPrice = (data: any) => {
    if (data?.cooperationMode === '分佣') {
        return data?.price
    } else {
        return data?.costPrice
    }
}
// 根据不同部门返回不同的机制
const mechanism = () => {
    return props.row?.hmStockMechanismsList && props.row?.hmStockMechanismsList.length ? props.row?.hmStockMechanismsList : null
}

</script>

<style lang="less" scoped>
.listItem {
    padding: 10px;
    background: #fff;
    margin-bottom: 8px;
    display: flex;
    box-sizing: border-box;

    .listItem_left {
        width: 120px;
        height: 120px;
        margin-right: 10px;
        position: relative;
        border-radius: 5px;
        overflow: hidden;

        .img {
            width: 100%;
            height: 100%;
            background: #E5F0FF;
            object-fit: cover;
            vertical-align: middle;
        }

        .img_tag {
            width: 46px;
            height: 22px;
            background-image: url("@/assets/newui/productList/icon_duojizhi@2x.png");
            background-size: 100% 100%;
            border-radius: 2px 0px 2px 0px;
            position: absolute;
            top: 0px;
            left: 0px;
        }

        .describe_department {
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 22px;
            background: #EBF4FF;
            display: flex;
            align-items: center;
            justify-content: center;
            box-sizing: border-box;

            .van-image {
                width: 12px;
                height: 12px;
            }

            .coreName {
                line-height: 22px;
                font-weight: 500;
                font-size: 12px;
                color: #0094FF;
                margin-left: 5px;
            }
        }
    }

    .listItem_right {
        flex: 1;
        min-width: 0;
        display: flex;
        flex-flow: column;

        .top_box_title {
            display: flex;
            align-items: center;
            justify-content: space-between;

            .title {
                flex: 0.9;
                min-width: 0;
                height: 22px;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
                font-weight: 500;
                font-size: 16px;
                color: #1A1B1C;
            }

            .title_tag {
                padding: 5px 5px;
                border-radius: 2px;
                line-height: 12px;
                text-align: center;
                font-weight: 500;
                font-size: 12px;
            }

            .title_tag_lan {
                background: #EBF4FF;
                color: #0094FF;
            }

            .title_tag_lv {
                background: #E7FDEE;
                color: #19D11B;
            }

            .title_tag_hong {
                background: #FDE7E7;
                color: #FC2540;
            }

            .title_tag_cheng {
                background: #FFE9E1;
                color: #FF5A1A;
            }
        }

        .top_box_text {
            width: 100%;
            display: -webkit-box;
            -webkit-line-clamp: 1;
            -webkit-box-orient: vertical;
            overflow: hidden;
            text-overflow: ellipsis;
            font-weight: 400;
            font-size: 12px;
            color: #8492AD;
            word-break: break-all;
            margin-top: 5px;
        }

        .top_box_supplier {
            width: 100%;
            margin-top: 5px;
            display: flex;

            .top_box_supplier_text {
                max-width: 100%;
                display: flex;
                align-items: center;
                border-radius: 5px;
                box-sizing: border-box;
                padding: 3px 5px;
                background: #FFE9E1;
            }

            .top_box_supplier_img {
                width: 12px;
                height: 14px;
                margin-right: 5px;
            }

            .top_box_supplier_text_name {
                flex: 1;
                min-width: 0;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
                font-weight: 500;
                font-size: 12px;
                color: #FF5A1A;
            }
        }

        .top_box_number {
            margin-top: 5px;
            display: flex;
            align-items: center;

            .number_one {
                font-weight: 500;
                font-size: 18px;
                color: #FC2540;

                .one_span {
                    font-size: 12px;
                    font-weight: 400;
                }
            }

            .number_two {
                margin-left: 10px;
                height: 16px;
                background: linear-gradient(136deg, #E9D1A5 0%, #CEA46C 100%);
                border-radius: 2px;
                display: flex;

                .two_left {
                    width: 22px;
                    height: 16px;
                    background: #1B1714;
                    border-radius: 2px;
                    text-align: center;
                    line-height: 16px;
                    font-weight: 400;
                    font-size: 12px;
                    color: #CEA46C;
                }

                .two_right {
                    padding: 0 3px;
                    text-align: center;
                    line-height: 16px;
                    font-weight: 500;
                    font-size: 12px;
                    color: #1B1714;
                }
            }
        }

        .top_box_time {
            margin-top: 5px;
            display: flex;
            align-items: center;
            justify-content: space-between;

            .top_box_time_item {
                background: #FEF6E2;
                border-radius: 5px;
                padding: 4px 5px;
                box-sizing: border-box;
                display: flex;
                align-items: center;
                justify-content: center;
                font-weight: 400;
                font-size: 12px;
                color: #B5884A;
            }
        }
    }
}
</style>